<?php
    session_start();
    include "./config.php";    
    $username = $_POST['username3'];
    $safecode = $_POST['savecode2'];
	$safeanser = $_POST['safeanser'];
	$ip = getenv("REMOTE_ADDR"); 
	$showtime = date("Y-m-d H:i:s");
    mysql_select_db($main_db,$conn) or die ("Can not connect DataBase:".mysql_error());
    if(!$username || !$safecode || !$safeanser)
    {
        echo "Please Input your safecode and safeanser";
    }
    else
    {
        $result = mysql_query("select * from userinfo where username='$username'",$conn);
        $row =  mysql_fetch_array($result);
        if($safecode == $row[3] && $safeanser == $row[4])
        {
			echo "Your PassWord is ";
			echo $row[2];
			mysql_query("insert into Findpasswordlog(username,safecode,safeanswer,userip,findtime,findstat)
            values('$username','$safecode','$safeanser','$ip','$showtime','1')",$conn);

        }
        else
        {
            echo "Wrong Username or Safecode try again";
			mysql_query("insert into Findpasswordlog(username,safecode,safeanswer,userip,findtime,findstat)
            values('$username','$safecode','$safeanser','$ip','$showtime','0')",$conn);
        }

    }

?>
